home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
demos
/
GL
/
curve
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
9KB
|
379 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
*
* menu.c
*
* Part of the "Curve Demo"
* by Howard Look for Silicon Graphics
*
* June, 1989
*
* This file contains the routines used for initializing and
* maintaining the menus that make up the curve demo.
*
*/
#include <stdio.h>
#include <gl.h>
#include <device.h>
#include <math.h>
#include "event.h"
#include "curve.h"
/* Prototypes */
void init_menus(void);
void do_menus(void);
void remake_curve_menu(void);
void remake_basis_menu(void);
void remake_display_menu(void);
void remake_precision_menu(void);
void remake_speed_menu(void);
void remake_style_menu(void);
void remake_options_menu(void);
void remake_whizbang_menu(void);
void remake_all_menus(void);
extern void set_defaults(void);
extern void change_display(int);
extern void toggle_markers(void);
extern void toggle_hulls(void);
extern void toggle_motion(void);
extern void toggle_smear(void);
extern void change_basis(int);
extern void change_precision(int);
extern void change_speed(int);
extern void change_style(int);
extern void change_whizbang(int);
extern void quit(void);
extern void clear_window(void);
extern void help(void);
extern void end_help(void);
/* Declare menus */
static long curve_menu; /* Top level Menu */
static long basis_menu; /* Curve Basis - Bezier, Cardinal, B-Spline */
static long display_menu; /* 2D or 3D display */
static long options_menu; /* Program options */
static long precision_menu; /* Sub-options menu : Spline precision */
static long speed_menu; /* Sub-options menu : Motion speed factor */
static long style_menu; /* Sub-options menu: Line style */
static long whizbang_menu; /* Sub-options menu: Whizbang demos */
/* Environment variables */
extern
int curve_basis,
display_mode,
curve_precision,
speed,
line_style,
whizbang;
extern
Boolean markers,
hulls,
motion,
smear;
/*
* Allocate and initialize the menus, then tell the event manager
* to watch for right mouse button clicks.
*/
void init_menus(void)
{
curve_menu = newpup();
basis_menu = newpup();
display_menu = newpup();
precision_menu = newpup();
speed_menu = newpup();
style_menu = newpup();
whizbang_menu = newpup();
options_menu = newpup();
set_initial_conditions();
remake_all_menus();
add_event(ANY, RIGHTMOUSE, DOWN, do_menus, NULL);
qdevice(RIGHTMOUSE);
}
/*
* Called by the event manager whenever the right mouse button is
* pressed.
*/
void do_menus(void)
{
end_help();
dopup(curve_menu);
}
/*
* Rebuild the entire menu tree. Because menu items change based upon
* user input, sub-menus are rebuilt as necessary. Then the root menu
* is rebuilt using these chaned sub-menus.
*/
void remake_curve_menu(void)
{
freepup(curve_menu);
curve_menu = newpup();
addtopup(curve_menu, "Curve %t"); /* title */
addtopup(curve_menu, "Curve Basis %m", basis_menu);
addtopup(curve_menu, "Display Mode %m", display_menu);
addtopup(curve_menu, "Options %m", options_menu);
addtopup(curve_menu, "Set Defaults %f", set_defaults);
addtopup(curve_menu, "Clear Window %f", clear_window);
addtopup(curve_menu, "Help %f", help);
addtopup(curve_menu, "Quit Curve %f", quit);
}
/*
* Remakes the menu which giving control over the curve basis
* matrix.
*/
void remake_basis_menu(void)
{
char menu_string[32];
freepup(basis_menu);
basis_menu = newpup();
addtopup(basis_menu, "Curve Basis %t %F", change_basis);
if (curve_basis == BEZIER)
sprintf(menu_string, "->Bezier Spline %%x%d", BEZIER);
else
sprintf(menu_string, " Bezier Spline %%x%d", BEZIER);
addtopup(basis_menu, menu_string);
if (curve_basis == CARDINAL)
sprintf(menu_string, "->Cardinal Spline %%x%d", CARDINAL);
else
sprintf(menu_string, " Cardinal Spline %%x%d", CARDINAL);
addtopup(basis_menu, menu_string);
if (curve_basis == BSPLINE)
sprintf(menu_string, "->B-Spline %%x%d", BSPLINE);
else
sprintf(menu_string, " B-Spline %%x%d", BSPLINE);
addtopup(basis_menu, menu_string);
}
/* Remake the menu giving control over the display mode, i.e. two
* dimensional or three dimensional.
*/
void remake_display_menu(void)
{
char menu_string[32];
freepup(display_menu);
display_menu = newpup();
addtopup(display_menu, "Display Mode %t %F", change_display);
if (display_mode == TWO_D)
sprintf(menu_string, "->Two Dimensional %%x%d", TWO_D);
else
sprintf(menu_string, " Two Dimensional %%x%d", TWO_D);
addtopup(display_menu, menu_string);
if (display_mode == THREE_D)
sprintf(menu_string, "->Three Dimensional %%x%d", THREE_D);
else
sprintf(menu_string, " Three Dimensional %%x%d", THREE_D);
addtopup(display_menu, menu_string);
}
/* Remake the menu giving control over the precision over spline
* segments. MIN_PRECISION, MAX_PRECISION and PRECISION_STEP may
* be changed in curve.h, though they should reflect reasonable
* integer values.
*/
void remake_precision_menu(void)
{
char menu_string[16];
int i;
freepup(precision_menu);
precision_menu = newpup();
addtopup(precision_menu, "Segments per Spline %t %F",
change_precision);
for (i = MIN_PRECISION; i<=MAX_PRECISION; i+=PRECISION_STEP)
{
if (curve_precision == i)
{
sprintf(menu_string, "->%d %%x%d", i, i);
addtopup(precision_menu, menu_string);
}
else
{
sprintf(menu_string, " %d %%x%d", i, i);
addtopup(precision_menu, menu_string);
}
}
}
/* Remakes the menu giving control over the speed of motion, when
* active. Speed is increased by simply multiplying the motion offset
* for each control point by this speed constant. MIN_SPEED, MAX_SPEED
* and SPEED_STEP may be changed in curve.h, but should reflect
* reasonable integer values.
*/
void remake_speed_menu(void)
{
char menu_string[16];
int i;
freepup(speed_menu);
speed_menu = newpup();
addtopup(speed_menu, "Motion Speed %t %F", change_speed);
for (i = MIN_SPEED; i<=MAX_SPEED; i+=SPEED_STEP)
{
if (speed == i)
{
sprintf(menu_string, "->%d %%x%d", i, i);
addtopup(speed_menu, menu_string);
}
else
{
sprintf(menu_string, " %d %%x%d", i, i);
addtopup(speed_menu, menu_string);
}
}
}
/* Remakes the menu giving control over line style used to draw the
* curves. The patterns are defined in curve.h, and may be changed.
*/
void remake_style_menu(void)
{
char menu_string[32];
freepup(style_menu);
style_menu = newpup();
addtopup(style_menu, "Line Style %t %F", change_style);
if (line_style == SOLID)
sprintf(menu_string, "->Solid %%x%d", SOLID);
else
sprintf(menu_string, " Solid %%x%d", SOLID);
addtopup(style_menu, menu_string);
if (line_style == DOTTED)
sprintf(menu_string, "->Dotted %%x%d", DOTTED);
else
sprintf(menu_string, " Dotted %%x%d", DOTTED);
addtopup(style_menu, menu_string);
if (line_style == DASHED)
sprintf(menu_string, "->Dashed %%x%d", DASHED);
else
sprintf(menu_string, " Dashed %%x%d", DASHED);
addtopup(style_menu, menu_string);
}
void remake_whizbang_menu(void)
{
char menu_string[32];
freepup(whizbang_menu);
whizbang_menu = newpup();
addtopup(whizbang_menu, "Whizbangs %t %F", change_whizbang);
sprintf(menu_string, "Coil %%x%d", COIL);
addtopup(whizbang_menu, menu_string);
sprintf(menu_string, "Bed Spring %%x%d", BEDSPRING);
addtopup(whizbang_menu, menu_string);
sprintf(menu_string, "Doughnut %%x%d", DOUGHNUT);
addtopup(whizbang_menu, menu_string);
}
/* Remakes the options menu, which includes some of the above menus as
* sub-menus and is itself a sub-menu to the root menu.
*/
void remake_options_menu(void)
{
freepup(options_menu);
options_menu = newpup();
addtopup(options_menu, "Options %t");
if (motion == ON)
addtopup(options_menu, "Turn Motion Off %f",
toggle_motion);
else
addtopup(options_menu, "Turn Motion On %f", toggle_motion);
if (markers == ON)
addtopup(options_menu, "Turn Markers Off %f",
toggle_markers);
else
addtopup(options_menu, "Turn Markers On %f", toggle_markers);
if (hulls == ON)
addtopup(options_menu, "Turn Hulls Off %f",
toggle_hulls);
else
addtopup(options_menu, "Turn Hulls On %f", toggle_hulls);
if (smear == ON)
addtopup(options_menu, "Turn Smear Off %f",
toggle_smear);
else
addtopup(options_menu, "Turn Smear On %f", toggle_smear);
addtopup(options_menu, "Precision %m", precision_menu);
addtopup(options_menu, "Speed %m", speed_menu);
addtopup(options_menu, "Line Style %m", style_menu);
addtopup(options_menu, "Whizbangs %m", whizbang_menu);
}
void remake_all_menus()
{
remake_basis_menu();
remake_display_menu();
remake_precision_menu();
remake_speed_menu();
remake_style_menu();
remake_whizbang_menu();
remake_options_menu();
remake_curve_menu();
}